package com.srv.persistence;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import com.srv.common.NodeField;
import com.srv.model.Node;
import com.srv.util.ObjectField;

import junit.framework.TestCase;

public class NodePersistenceTestCase extends TestCase {
	
	public void testNodePersistenceTest() throws PersistenceException{
		INodePersistence persistence = PersistenceFactory.getNodePersistence();
		
		String nid = UUID.randomUUID().toString();
		String tid = "3df5cc1c-3f93-47da-b301-70ed317dd08a";
		Node node = new Node();
		node.pid = 24;
		node.nodeID = nid;
		node.travelID = tid;
		node.latitude = 1231122.123;
		List<String> list = new ArrayList<String>();
		list.add("http://www.123.com");
		list.add("http://www.456.com");
		list.add("http://www.789.com");
		node.img_Inner_URI = list;
		node = persistence.insertNode(node);
		assertEquals(nid, node.nodeID);
		
		node = persistence.getNode(24, nid);
		assertNotNull(node);
		
		Map<ObjectField, Object> map = new HashMap<ObjectField, Object>();
		map.put(NodeField.TAG, "标题");
		node.img_Inner_URI.add("http://www.101112.com");
		
		//更新list的两种方式都可以
		//1
//		map.put(NodeField.IMG_INNER_URI, Node.listToString(node.img_Inner_URI));
		
		//2
		map.put(NodeField.IMG_INNER_URI, node.getImgInnerURI());
		boolean b = persistence.updateNode(24, node.nodeID, map);
		assertTrue(b);
	}
}
